const cloud = require('wx-server-sdk')
cloud.init()

exports.main = async (event, context) => {
  const { openid } = event
  const db = cloud.database()
  
  try {
    // 查询用户是否存在
    const { data } = await db.collection('users')
      .where({ _openid: openid })
      .get()
    
    return {
      isValid: data.length > 0,
      userInfo: data[0] || null
    }
  } catch (error) {
    console.error('检查登录状态失败:', error)
    return {
      isValid: false,
      userInfo: null
    }
  }
} 